<?php

/**
 * A view that only generates output 
 * This view is/can be used from several controllers
 * Public method 'generateLoginBox', takes no arguments
 */
class LoginView {
  	
  //Constants to obtain values from login form	
  const username = "UserName";
  const password = "Password";
  const remember = "remember";
  
  const loginButton = "Login";
  const logoutButton = "Logout";
  
  /**
   * @return XHTML - Div containing login boxes and submitbutton
   */
  public function generateLoginBox() {
    $form = "
	    	<div class='loginDiv'>
		    	<form action='' method='get'>
		    		  <fieldset>
					    <legend>Enter Username and Password:</legend>
					    <label for='UserName'>Username:</label>
					    <input type='text' size='30' id='UserName' name='".LoginView::username."'/><br />
					    
					    <label for='PassWord'>Password:</label>
					    <input type='password' size='30' id='PassWord' name='".LoginView::password."'/><br />
					    
					    <input type='checkbox' name='".LoginView::remember."' value='Remenber me'>Remember me!</input><br />
					    
					    <input type='Submit' name='".LoginView::loginButton."' value='Login' />
					  </fieldset>
				</form>
		    <div/>
		    ";
		return $form;
  }
  
  /**
   * @return submitbutton -> logout
   */
  public function generateLogoutButton(){
  	return "<form action='' method='get'><input type='Submit' name='".LoginView::logoutButton."' value='Logout' /></form>";	
  }
  
  public function getUserName(){
  	//Check if username has a value	
  	if (isset( $_GET[LoginView::username]) == true) {
      //it it does, return it
      return $_GET[LoginView::username];
    } 
	//else return false
    return FALSE;	
  }
  
  public function getPassword(){
  	//Check if password has a value	
  	if (isset( $_GET[LoginView::password]) == true) {
      //it it does, return it
      return $_GET[LoginView::password];
    } 
	//else return false
    return FALSE; 	
  }

    public function getRememberStatus(){
  	//Check if password has a value	
  	if (isset( $_GET[LoginView::remember]) == true) {
      //it it does, return true
      return true;
    } 
	//else return false
    return FALSE; 	
  }
    
  public function triedToLogIn(){
  	//Check if login has been clicked
  	if (isset($_GET[LoginView::loginButton]) == true){
  		//If it has, return true	
  		return true;
  	}
  	//If not, return false
  	return false;
  }
  
  public function triedToLogOut(){
  	//Check if Logout button has been clicked
	if(isset($_GET[LoginView::logoutButton]) == true){
		//If it has, return true	
		return true;
	}
	//If not, return false
	return false;
  }

}